home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
dev
/
lang
/
fpcsrc.lha
/
fpc
/
compiler
/
ag68kmit.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-09-24
|
26KB
|
638 lines
{
$Id: ag68kmit.pas,v 1.1.1.1.2.4 1998/09/14 18:55:48 carl Exp $
Copyright (c) 1998 by the FPC development team
This unit implements an asmoutput class for MIT syntax with
Motorola 68000 (for MIT syntax TEST WITH GAS v1.34)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************
What's to do:
o Verify if this actually work as indirect mode with name of variables
o write lines numbers and file names to output file
o generate debugging informations
}
unit ag68kmit;
interface
uses aasm,assemble;
type
pm68kmitasmlist=^tm68kmitasmlist;
tm68kmitasmlist = object(tasmlist)
procedure WriteTree(p:paasmoutput);virtual;
procedure WriteAsmList;virtual;
end;
implementation
uses
dos,globals,systems,cobjects,m68k,
strings,files,verbose
{$ifdef GDB}
,gdb
{$endif GDB}
;
const
line_length = 70;
var
infile : pextfile;
includecount,lastline : longint;
function getreferencestring(const ref : treference) : string;
var
s : string;
begin
s:='';
if ref.isintvalue then
s:='#'+tostr(ref.offset)
else
with ref do
begin
{ symbol and offset }
if (assigned(symbol)) and (offset<>0) then
Begin
s:=s+'('+tostr(offset)+symbol^;
end
else
{ symbol only }
if (assigned(symbol)) and (offset=0) then
Begin
s:=s+'('+symbol^;
end
else
{ offset only }
if (symbol=nil) and (offset<>0) then
Begin
s:=s+'('+tostr(offset);
end
else
{ NOTHING - put zero as offset }
if (symbol=nil) and (offset=0) then
Begin
s:=s+'('+'0';
end
else
InternalError(10004);
if (index<>R_NO) and (base=R_NO) and (direction=dir_none) then
InternalError(10004)
else if (index=R_NO) and (base<>R_NO) and (direction=dir_inc) then
begin
if (scalefactor = 1) or (scalefactor = 0) then
Begin
if offset<>0 then
s:=mit_reg2str[base]+'@+'+s+')'
else
s:=mit_reg2str[base]+'@+';
end
else
InternalError(10002);
end
else if (index=R_NO) and (base<>R_NO) and (direction=dir_dec) then
begin
if (scalefactor = 1) or (scalefactor = 0) then
Begin
if offset<>0 then
s:=mit_reg2str[base]+'@-'+s+')'
else
s:=mit_reg2str[base]+'@-';
end
else
InternalError(10003);
end
else if (index=R_NO) and (base<>R_NO) and (direction=dir_none) then
begin
if (offset=0) and (symbol=nil) then
s:=mit_reg2str[base]+'@'
else
s:=mit_reg2str[base]+'@'+s+')';
end
else if (index<>R_NO) and (base<>R_NO) and (direction=dir_none) then
begin
s:=mit_reg2str[base]+'@'+s+','+mit_reg2str[index]+':L';
if (scalefactor = 1) or (scalefactor = 0) then
s:=s+')'
else
s:=s+':'+tostr(scalefactor)+')';
end
else
if assigned(symbol) then
Begin
s:=symbol^;
if offset<>0 then
s:=s+'+'+tostr(offset);
end
{ this must be a physical address }
else
s:=s+')';
{ else if NOT assigned(symbol) then
InternalError(10004);}
end; { end with }
getreferencestring:=s;
end;
function getopstr(t : byte;o : pointer) : string;
var
hs : string;
i: tregister;
begin
case t of
top_reg : getopstr:=mit_reg2str[tregister(o)];
top_ref : getopstr:=getreferencestring(preference(o)^);
top_reglist: begin
hs:='';
for i:=R_NO to R_FPSR do
begin
if i in tregisterlist(o^) then
hs:=hs+mit_reg2str[i]+'/';
end;
delete(hs,length(hs),1);
getopstr := hs;
end;
top_const : getopstr:='#'+tostr(longint(o));
top_symbol :
{ compare with i386, where a symbol is considered }
{ a constant. }
begin
hs[0]:=chr(strlen(pchar(pcsymbol(o)^.symbol)));
move(pchar(pcsymbol(o)^.symbol)^,hs[1],byte(hs[0]));
{ inc(byte(hs[0]));}
if pcsymbol(o)^.offset>0 then
hs:=hs+'+'+tostr(pcsymbol(o)^.offset)
else if pcsymbol(o)^.offset<0 then
hs:=hs+tostr(pcsymbol(o)^.offset);
getopstr:=hs;
end;
else internalerror(10001);
end;
end;
function getopstr_jmp(t : byte;o : pointer) : string;
var
hs : string;
begin
case t of
top_reg : getopstr_jmp:=mit_reg2str[tregister(o)];
top_ref : getopstr_jmp:=getreferencestring(preference(o)^);
top_const : getopstr_jmp:=tostr(longint(o));
top_symbol : begin
hs[0]:=chr(strlen(pchar(pcsymbol(o)^.symbol)));
move(pchar(pcsymbol(o)^.symbol)^,hs[1],byte(hs[0]));
if pcsymbol(o)^.offset>0 then
hs:=hs+'+'+tostr(pcsymbol(o)^.offset)
else if pcsymbol(o)^.offset<0 then
hs:=hs+tostr(pcsymbol(o)^.offset);
getopstr_jmp:=hs;
end;
else internalerror(10001);
end;
end;
{****************************************************************************
T68kGASASMOUTPUT
****************************************************************************}
var
{ different types of source lines }
n_line : byte;
const
ait_const2str:array[ait_const_32bit..ait_const_8bit] of string[8]=
(#9'.long'#9,'',#9'.short'#9,#9'.byte'#9);
procedure tm68kmitasmlist.WriteTree(p:paasmoutput);
var
hp : pai;
ch : char;
consttyp : tait;
s : string;
pos,l,i : longint;
found : boolean;
{$ifdef GDB}
funcname : pchar;
linecount : longint;
{$endif GDB}